package day05.localDate;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/25
 * 8.新闻类：标题，内容，时间   三个属性。 有10条新闻，按照时间的降序排列。
 */
public class News {
    private String title;
    private String text;
    private LocalDate date;
    public News() {

    }

    public News(String title, String text, LocalDate date) {
        this.title = title;
        this.text = text;
        this.date = date;
    }


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public LocalDate getDate() {
        return date;
    }

    public void Date(LocalDate localDate) {
        this.date = localDate;
    }

    public String toString() {
        return "News{title = " + title + ", text = " + text + ", localDate = " + date + "}";
    }

    public static void main(String[] args) {
        News[] news = new News[10];
        for (int i = 0; i < 10; i++) {
            news[i] = new News("Title" + i, "Text" + i, LocalDate.of(2025,4,(16+i)));
        System.out.println(news[i]);
        }

        Arrays.sort(news, new Comparator<News>() {
            @Override
            public int compare(News o1, News o2) {
                return o2.getDate().compareTo(o1.getDate());
            }
        });
        System.out.println("------------------------排序后----------------------------");
        for (int i = 0; i < 10; i++) {
            System.out.println(news[i]);
        }

    }



}
